<?php

chdir(dirname(__FILE__));
// error_reporting(E_ERROR);
// require_once ("../../config.php");//引入配置
// require_once ("../../log.php");
// require_once ("../api_tool.php");

include "../sdk_pdd/DdkSdk.php";

/** 
 * @name Api接口demo（php版）
 * @desc 本接口列表，只是用于系统处理拼拼多多的订单转链
 * 
 */

define("AppKey", "3e377e391163463baf70a810df290c21");
define("AppSecret", "31c4e93e5ac3234682f6011417ca9415a15215f3");

// 拼多多多多进宝商品查询
function getPddDdkGoodsSearch($cat_id, $keyword = '', $page = 1, $page_size = 30, $sort_type = 2) {
    $c = new DdkClient;
    $c->appkey = AppKey;
    $c->secretKey = AppSecret;
    $req = new DdkGoodsSearchRequest;
    $req->setCatId($cat_id);
    $req->setKeyword($keyword);
    $req->setPage($page);
    $req->setPageSize($page_size);
    $req->setSortType($sort_type);
    $resp = $c->execute($req);
    return object_to_array($resp);
}

// 拼多多进宝商品推荐API
function getPddDdkGoodsRecommend($channel_type) {
	$c = new DdkClient;
	$c->appkey = AppKey;
	$c->secretKey = AppSecret;
	$req = new DdkGoodsRecommendGetRequest;
	$req->setChannelType($channel_type);
	$resp = $c->execute($req);
	return object_to_array($resp);
}

// 拼多多进宝商品详情查询
function getPddDdkGoodsDetail($pid, $goods_id_list) {
	LOGINFO($pid, "=== pid");
	LOGINFO($goods_id_list, "=== goods_id_list");
	$c = new DdkClient;
	$c->appkey = AppKey;
	$c->secretKey = AppSecret;
	$req = new DdkGoodsDetailRequest;
	$req->setPid($pid);
	$req->setGoodsIdList($goods_id_list);
	$resp = $c->execute($req);
	return object_to_array($resp);
}

// 拼多多进宝转链接口
function getPddDdkGoodsZsUnitUrlGen($pid, $source_url) {
	$c = new DdkClient;
	$c->appkey = AppKey;
	$c->secretKey = AppSecret;
	$req = new DdkGoodsZsUnitUrlGenRequest;
	$req->setPid($pid);
	$req->setSourceUrl($source_url);
	$resp = $c->execute($req);
	return object_to_array($resp);
}

// 拼多多进宝推广链接生成
function getPddDdkGoodsPromotionUrlGenerate($pid, $goods_id_list) {
	$c = new DdkClient;
	$c->appkey = AppKey;
	$c->secretKey = AppSecret;
	$req = new DdkGoodsPromotionUrlGenerateRequest;
	$req->setPid($pid);
	$req->setGoodsIdList($goods_id_list);
	$resp = $c->execute($req);
	return object_to_array($resp);
}

?>